import hx.display.Quad;
import hx.events.MouseEvent;
import hx.display.MovieClip;
import hx.display.FPS;
import hx.display.Image;
import hx.assets.Assets;
import hx.display.Stage;

class GameStage extends Stage {
	override function onStageInit() {
		super.onStageInit();
		// 代码开始的地方...
		var loader = new MovieClipJsonLoader("assets/qq.json");
		loader.onComplete((atlas) -> {
			trace("加载成功");
			for (i in 0...10000) {
				var mc = atlas.createPlayer();
				this.addChild(mc);
				mc.play("move");
				mc.x = Math.random() * stage.stageWidth;
				mc.y = Math.random() * stage.stageHeight;

				var aniamte = [
					for (key in mc.animates.keys()) {
						key;
					}
				];
				var index = 0;
				mc.addEventListener(MouseEvent.CLICK, (e) -> {
					index++;
					if (index >= aniamte.length) {
						index = 0;
					}
					mc.play(aniamte[index]);
				});
			}

			var fps = new FPS();
			this.topView.addChild(fps);
		}).onError(err -> {
			trace("加载失败", err);
		});
	}
}
